<jsp:include page="/templates/header.jsp"/>
<%@page import="controller.*"%>
<%@page import="database.Queries"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.sql.Connection" %>
<%@page import="database.Connect" %>
<%@page import="java.sql.SQLException"%>

<script type="text/javascript" src="/salonmorandsmigi/js/jquery.editable-1.3.3.js"></script>
<script type="text/javascript" src="/salonmorandsmigi/js/sinfo.js"></script>

<%String username = request.getParameter("name");
  Connection con = null;
  Student s = null;
  try{
	  con = Connect.getConnection();
	  con.setAutoCommit(false);
	  s = Queries.createStudent(con,username);
	  con.commit();
  }catch (SQLException e){
	  con.rollback();
	  e.printStackTrace();
	  out.write("SERVER ERROR! PLEASE TRY AGAIN");
	  return;
  }
  finally{
	  if (con!=null){
		  con.setAutoCommit(true);
		  con.close();
	  }
  }
  if (s==null){%>	
	Student doesn't exists
  <%}
  else {%>
  	 <h1><%=s.getUsername()%>'s Details</h1>
  	 <div class="details">
	  	 <p><strong>username:</strong>&nbsp;&nbsp;<%=s.getUsername()%></p>
	  	 <p><strong>password:</strong>&nbsp;&nbsp;<%=s.getPassword()%></p>  
	  	 <p><strong>full name:</strong>&nbsp;&nbsp;<%=s.getFullname()%></p> 
	  	 <p><strong>phone number:</strong>&nbsp;&nbsp;<%=s.getPhone()%></p> 
  	 </div>
  <%} %>
  <%
  	LinkedList<Course> courses = s.getCourses();
    if (courses==null){%>
    	<div class="rediv">
    		<h2>The student isn't registered to any course</h2>
    	  </div>
    <%} 
    else {%>
    	<div id="accordion">
    	<% for (int i=0;i<courses.size();i++){ 
    		Course current = courses.get(i);
    	%>
    		<h3><a href="#"><%=current.getName()%></a></h3>
		    <div>
		    	<p>Credit pts.: <%=current.getPointNum()%></p>
		    	<p>Group number: <%=current.getGroupNum() %></p>
		    	<button id=<%=current.getName()%>>Course Page</button>
		    </div>
		   
    	<%}%>
		</div>
    <%} %>
    
<jsp:include page="/templates/sidebar.jsp"/>
<jsp:include page="/templates/footer.jsp"/>